function openComDB(name, path, callback) {
 
    plus.sqlite.openDatabase({
        name: name,
        path: path,
        success: function(e) {
            // plus.nativeUI.alert('打开数据库成功'); 
            callback(e)
        },
        fail: function(e) {
            // plus.nativeUI.alert("打开数据库失败"); 
            callback(e);
        }
    })
}
 
function executeSQL(name, sql, callback) {
 
    plus.sqlite.selectSql({
        name: name,
        sql: sql,
        success: function(e) {
            // console.log("查询数据库:" + name + ",表:" + sql + ";的"); 
            // console.log("查询数据库:"+JSON.stringify(e)); 
            callback(e);
        },
        fail: function(e) {
            // console.log("查询数据库失败:" + JSON.stringify(e));
            callback(e);
        }
    })
}

          function dbInit() {
                //创建表
                  var sqlTable = 'CREATE TABLE IF NOT EXISTS "message" (';
					sqlTable+=' "id" text NOT NULL,';
					sqlTable+=' "msg" text,';
					sqlTable+=' "avatar" text,';
					sqlTable+=' "photoUrl" text,';
					sqlTable+=' "username" text,';
					sqlTable+=' "picContent" text,';
					sqlTable+=' "picOri" text,';
					sqlTable+=' "isMe" text,';
					sqlTable+=' "type" integer(11),';
					sqlTable+=' "status" integer(11),';
					sqlTable+=' "sendTime" text,';
					sqlTable+=' "fromUserId" text,';
					sqlTable+=' "toUserId" text,';
					sqlTable+=' "fromUser" text,';
					sqlTable+=' "toUser" text,';
					sqlTable+=' "read" text,';
					sqlTable+='  PRIMARY KEY ("id")';
					sqlTable+=' )';
 
					executeSQL('ppchatmsg', sqlTable, res => {
						console.log('' + res);
					})
            }


 
function closeComDB(name, path, callback) {
 
    plus.sqlite.closeDatabase({
        name: name,
        path: path,
        success: function(e) {
            // plus.nativeUI.alert('打开数据库成功'); 
            callback(e)
        },
        fail: function(e) {
            // plus.nativeUI.alert("打开数据库失败"); 
            callback(e);
        }
    })
}
 
 
export {
    openComDB,
    closeComDB,
    executeSQL,
    dbInit
}